package com.panshi.controller;

import com.panshi.service.ISysUserService;
import com.panshi.vo.PagingVO;
import com.panshi.vo.ResultVO;
import com.panshi.vo.SysUserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping(path = "sysuser")
@Slf4j
public class SysUserController {

    @Autowired
    private ISysUserService iSysUserService;


    @RequestMapping("/view/userList")
    @ResponseBody
    public ResultVO<List<SysUserVO>> findSysUserList(String limit, String page) throws InterruptedException {
        PagingVO<?> pagingVO = new PagingVO<>();
        pagingVO.setPageSize(Integer.valueOf(limit));
        pagingVO.setCurrentPage(Integer.valueOf(page));
        ResultVO<List<SysUserVO>> resultVO = iSysUserService.findSysUserList(pagingVO);
        return resultVO;
    }

    @PutMapping("/edit/status")
    @ResponseBody
    public ResultVO<String> editSysUserStatus(@RequestBody SysUserVO sysUserVO){
        iSysUserService.editSysUserStatus(sysUserVO);
        ResultVO<String> resultVO = new ResultVO<>();
        resultVO.setCode("200");
        resultVO.setMsg("该用户已被禁用");
        return resultVO;
    }

    @PutMapping("/edit/sysuser")
    @ResponseBody
    public ResultVO<String> editSysUserInfo(@RequestBody SysUserVO sysUserVO){
        return iSysUserService.editSysUserInfo(sysUserVO);
    }


    @DeleteMapping("/del/{id}")
    @ResponseBody
    public ResultVO<String> delSysUserInfo(@PathVariable long id){
        ResultVO<String> resultVO = iSysUserService.delSysUserInfo(id);
        return resultVO;
    }

    @PostMapping("/add")
    @ResponseBody
    public ResultVO<String> insertSysUser(@RequestBody SysUserVO sysUserVO){
        log.info("sysUserVO的值{}  ",sysUserVO);
        ResultVO<String> resultVO = iSysUserService.insertSysUserInfo(sysUserVO);
        return resultVO;
    }

}
